<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加外采购商品</title>
<script language="javascript">
	//$.validator.setDefaults({
	//    submitHandler: function() {
	//      $("#otherForm").submit();
	//    }
	//});
	$().ready(function() {
		$("#sku").focus();
		$("#otherForm").validate();
	});

	$.validator.setDefaults({
		submitHandler: function(form) { form.submit(); }
	});
	function JqValidate()
	{
		return $( '#otherForm' ).validate();
	}
	function submitBtn()
	{
		if( JqValidate()){
			//	alert(1);
			$( '#otherForm' ).submit();
		}
	}
	/*function showinput_pro()
	 {
	 var sku = $("#sku").val();
	 var goodstypeID = $("#goodstypeID").val();
	 $.post("/product/ajaxbutton", {"op": "showattr","id":goodstypeID},function(data){
	 if(data !=201)
	 {
	 for(var s=0;s<data.length;s++)
	 {
	 attr+=data[s].attr_name;
	 str+="<td>"+attr+"</td>";
	 }
	 alert(str);
	 }
	 },"json");
	 }*/
	var totalnum = 1;
	function showinputPro()
	{
		var inputn = document.getElementById("showsuppliertd");
		var str=inputn.innerHTML;
		var num=1;
		var tonum = 1;
		for(var i=1;i<=num;i++){
			tonum=tonum+i;
			str += "<tr id=las"+tonum+">";
			str+="<td class=\"head1\" width=\"10%\">采购商家名称</td>";
			str+="<td class=\"head0\" width=\"40%\"><input id=\"businessman\" name=\"businessman[]\" class=\"width200\" type=\"text\"></td>";
			str+="<td class=\"head1\" width=\"10%\">采购连接</td>";
			str+="<td class=\"head0\"><input id=\"businessmanline\" name=\"businessmanline[]\" class=\"width400\" type=\"text\"></td>";
			str+="<td>&nbsp;&nbsp;<a href=javascript:void(0) onclick=delfileinput("+tonum+")><span style=\"padding:5px 0 0\" class=\"c9\">移除</span></a></td>";
			str+="</tr>";
		}
		$("#showsuppliertd").before(str);

	}
	function showinput()
	{
		var inputn = document.getElementById("input1");
		var str=inputn.innerHTML;
		var num=1;
		var sku = $("#sku").val();
		var attr="";
		var goodstypeID = $("#goodstypeID").val();

		for(var i=1;i<=num;i++){
			totalnum=totalnum+i;
			str += "<tr class=\"italic\" id=las"+totalnum+">";
			str+="<td><input type=\"text\" name=\"subsku[]\" style=\"text-transform:uppercase;\" id=\"subsku\" value=\""+sku+"\" class=\"width200\" placeholder='请输入子SKU尺码'></td>";
			if(goodstypeID)
			{
				$.ajaxSetup({async: false});	//同步
				$.post("/product/ajaxbutton", {"op": "showattr","id":goodstypeID},function(data){
					if(data !=201)
					{
						for(var s=0;s<data.length;s++)
						{
							attr+="<td>"+data[s].attr_name+"</td>";
							if(data[s].attr_input_type==0)
							{
								attr+="<td><input type=\"text\" name=attr_values"+data[s].attr_id+"[] id=attr_values"+data[s].attr_id+" class=\"width100\"></td>";
							}else{
								var words = data[s].attr_values.split('\r\n');
								if(data[s].attr_values_code){
									var wordscode= data[s].attr_values_code.split('\r\n');
								}else{
									var wordscode="";
								}
								var tmpwords="<select name=attr_values"+data[s].attr_id+"[] id=attr_values"+data[s].attr_id+" class=\"selection\" style=\"width:200px;\" onchange=\"getcode(this,"+totalnum+")\">";
								tmpwords+='<option value="" code="99999999AA">请选择</option>';
								for(var k=0;k<words.length;k++)
								{
									if(wordscode=='')
									{
										tmpwords+=" <option value=\""+words[k]+"\" code='99999999AA'>"+words[k]+"</option>";
									}else{
										tmpwords+=" <option value=\""+words[k]+"\" code=\""+wordscode[k]+"\">"+words[k]+"</option>";
									}

								}
								tmpwords+=" </select>";
								attr+="<td>"+tmpwords+"</td>";
							}

						}

					}
				},"json");
			}

			str+=attr;
			str+="<td><input type=\"text\" name=\"subskuinfo[]\" id=\"subskuinfo\"  class=\"width200\" placeholder='请输入子sku尺码信息'></td>";
			str+="<td>&nbsp;&nbsp;<a href=javascript:void(0) onclick=delfileinput("+totalnum+")><span style=\"padding:5px 0 0\" class=\"c9\">移除</span></a></td>";
			str+="</tr>";
		}
		$("#input1").before(str);

	}
	function getcode(obj,sut)
	{
		var sku = $("#sku").val();
		if(sku=="")
		{
			$("#skuerr").html('<br /><span style="color:#ff0000;">请填写SKU</span>');
			$("#sku").focus();
			return false;
		}
		//获取tr中的值
		var skuID = "";
		$("#las"+sut+" select").each(function()
		{
			var st= $(this).find("option:selected").attr("code");//遍历获取自定义的值；
			if(st =='99999999AA')
			{

			}else{
				skuID+=st+"-";
			}
		});
		//去除最后一个
		if(skuID){
			var skuID = skuID.substr(0,skuID.length-1);//除去最后一个“，”
			skuID = sku+"-"+skuID;
			$("#las"+sut+" input").val(skuID);
		}
		return;
	}

	function delfileinput(id)
	{
		if(confirm("确定移除？"))
		{
			$("#las"+id).remove();
		}
	}
	function cleart()
	{
		$("tr").remove(".italic");
	}
	function getSku()
	{
		var sku = $("#sku").val();
		if(sku){
			$("#skuerr").html('<img src="/fuman/images/loaders/loader2.gif">');
			$.post("/product/ajaxbutton", {"op": "searchsku","sku":sku},function(data){
				if(data ==200)
				{
					$("#skuerr").html('');
				}else{
					if(data.red.saleNum>=5)
					{
						$("#skuerr").html('<font color=red>SKU['+sku+']已经存在！销量'+data.red.saleNum+',不允许保存</font>');
						$("#showbuttom").hide();
					}else{
						$("#skuerr").html('<font color=red>SKU['+sku+']已经存在！</font>');
					}
					//$("#sku").val('');
				}
			},"json");
		}
	}
	function issupplier()
	{
		var supplier = $("#supplier").val();
		if(supplier == 3)
		{
			$("#showsupplier").show();
		}else{
			$("#showsupplier").hide();
		}
	}
	$().ready(function() {
		$("#sku").focus();
		getsecondcate('{{$detail.p_secondclassid}}');
		getthirdcate('{{$detail.p_secondclassid}}','{{$detail.p_threeclassid}}');
	});
	function delsubsku(id) {
		$.post("/externalBuy/ajaxbutton", {"op": "delsubsku","id":id},function(data){
			if(data ==200)
			{
				window.location.reload();
			}else{
				alert("未知错误");return false;
			}
		},"json");
	}

function Newgetsecondcate(t)
{
	var bigclassID = $("#bigclassID").val();
	if(bigclassID)
	{
		$.post("/product/ajaxbutton", {"op": "selectcategory","sort_id":bigclassID},
		  function(data){
			
				if(data ==201)
				{
					
				}else{
					var tmp="<select name=\"secondclassID\" id=\"secondclassID\" class=\"selection\" style=\"width:200px;\" onChange=\"getcodecate()\">";
						tmp+='<option value="">请选择</option>';
					for(var i=0;i<data.length;i++)
					{
						if(t == data[i].id)
						{
							var st = "selected";
						}else{
							var st = "";
						}
						tmp+=" <option value=\""+data[i].id+"\" "+st+">"+data[i].cate_name+"</option>";
						
					}
					tmp+=" </select>";
					$("#showsecondcate").html(tmp);
				
				}
				
			
		   },"json");	
	}
}
function getcodecate()
{
	var bigclassID = $("#bigclassID").val();
	var secondclassID = $("#secondclassID").val();
	
	if(bigclassID && secondclassID)
	{
	$.post("/product/ajaxbutton", {"op": "getautoskunumber","bigclassID":bigclassID,"secondclassID":secondclassID},
		  function(data){
			  $("#sku").val(data);
			  getSku();
		   },"json");
	}
}
</script>
<body class="withvernav">
<div class="bodywrapper"> {{include file='/public/leftmenu.tpl'}}
	<div class="centercontent">
		<div class="pageheader notab">
			<h1 class="pagetitle">添加外采购商品</h1>
			<span class="pagedesc"></span>
			<div class="menulist">
				<ul class="profile_summary">
					<li class="current"><a href="/externalBuy/extBuyList">外采购商品列表</a></li>
				</ul>
			</div>
		</div>
		<!--pageheader-->

		<div id="contentwrapper" class="contentwrapper">
			<div id="basicform" class="subcontent">
				<form class="stdform stdform2"  id="otherForm" method="post" action="/externalBuy/saveExtProduct" enctype="multipart/form-data" >
					<table cellpadding="0" cellspacing="0" border="0" class="stdtable">
						<thead>
						<tr>
							<th colspan="2" class="head1">一、基础信息</th>
						</tr>
						</thead>
					</table>
					<table cellpadding="0" cellspacing="0" border="0" class="stdtable">
						<tbody>
						<tr>
							<td class="head1" width="120">商品分类 *</td>
							<td class="head0" colspan="3">
								{{if $detail.status gt 1}}
										{{foreach from=$categorylist item=res key=key}}
											{{if $detail.p_bigclassid == $res.id}}{{$res.cate_name}} {{/if}}
										{{/foreach}}

										{{if $detail.p_secondclassid}}
											{{foreach from=$category item=res key=key}}
												{{if $detail.p_secondclassid == $res.id}}->{{$res.cate_name}} {{/if}}
											{{/foreach}}
										{{/if}}

										{{if $detail.p_threeclassid}}
											{{foreach from=$category item=res key=key}}
												{{if $detail.p_threeclassid == $res.id}}->{{$res.cate_name}} {{/if}}
											{{/foreach}}
										{{/if}}
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									商品SKU*：
									{{$detail.sku}}
										<span id="skuerr"></span>
									<input type="hidden" name="sku" id="sku"  value="{{$detail.sku}}" >
								{{else}}
									<select name="bigclassID" id="bigclassID" class="selection" style="width:200px;"  onChange="Newgetsecondcate()"  required>
										<option value="">请选择</option>
										{{foreach from=$categorylist item=res key=key}}
											<option value="{{$res.id}}" {{if $detail.p_bigclassid eq $res.id}} selected{{/if}}>{{$res.cate_name}}</option>
										{{/foreach}}
									</select>
								&nbsp; <span id="showsecondcate"></span> &nbsp; <span id="showthirdcate"></span>
							商品SKU *
							<input type="text" name="sku" id="sku" class="width200" value="{{$detail.sku}}" {{if $detail.status gt 1}} readonly {{/if}} onKeyUp="this.value=this.value.replace(/[^\w_\w-]/g,'');" required onBlur="getSku()"  style="text-transform:uppercase;">
							<span id="skuerr"></span></td>
								{{/if}}
							</td>
						</tr>
						<!--
						{{if $detail.status gt 1}}
						<tr>
							<td class="head1">商品SKU *</td>
							<td colspan="3" class="head0">{{$detail.sku}}
								<span id="skuerr"></span></td>
						</tr>
						{{else}}
							<tr>
								<td class="head1">商品SKU *</td>
								<td colspan="3" class="head0"><input type="text" name="sku" id="sku" class="width200" value="{{$detail.sku}}" {{if $detail.status gt 1}} readonly {{/if}} onKeyUp="this.value=this.value.replace(/[^\w_\w-]/g,'');" required onBlur="getSku()"  style="text-transform:uppercase;">
									<span id="skuerr"></span></td>
							</tr>
						{{/if}}
						-->
						<tr>
							<td class="head1">商品名称 *</td>
							<td colspan="3" class="head0">
								<input type="text" name="goods_name"  id="goods_name" class="width200" value="{{$detail.p_parent_name}}" required>&nbsp;
								英文名称:<input type="text" name="en_goods_name" class="width200" value="{{$detail.p_en_goods_name}}">
								采购连接：
								<input type="text" name="address" id="address1" class="width400" required  value="{{$detail.address}}">
								 &nbsp;
								采购天数：
								<input type="text" name="buy_days" id="buy_days" class="width50" value="{{$detail.buy_days}}">&nbsp;天
							</td>
						</tr>
						<tr>
							<td class="head1" width="120">成本价格（元）</td>
							<td colspan="3" class="head0">
								<input type="text" name="costprice" id="costprice" class="width100" value="{{$detail.p_costprice}}" required>&nbsp;
								最低售价：<input type="text" name="sellprice" id="sellprice" class="width100" value="{{$detail.p_sellprice}}" required>&nbsp;
								供货商
								<input type="text" name="supplier" id="supplier" class="width200" required
								       value="{{$detail.supplier}}">&nbsp;
								联系人:
								<input type="text" name="contactperson" id="contactperson" class="width200"
								       value="{{$detail.contactperson}}">&nbsp;
								联系方式：
								<input type="text" name="phone" id="phone" class="width200" required
								       value="{{$detail.phone}}">
							</td>
						</tr>
						<tr>
							<td class="head1" width="120">重量 长宽高</td>
							<td colspan="3" class="head0">
								重量：<input type="text" name="weight" class="width100" value="{{$detail.weight}}" >&nbsp;克&nbsp;
								长度：<input type="text" name="length" class="width100" value="{{$detail.length}}">&nbsp;CM&nbsp;
								宽度：<input type="text" name="width" class="width100" value="{{$detail.width}}" >&nbsp;CM&nbsp;
								高度：<input type="text" name="heigth" class="width100" value="{{$detail.heigth}}">&nbsp;CM&nbsp;
							</td>
						</tr>
						<tr>
							<td class="head1">材料信息</td>
							<td class="head0" colspan="3">
								<textarea name="fabricinfo" cols="4" rows="2" required style="width: 300px;">{{$detail.fabricinfo}}</textarea>
								备注信息：
								<textarea name="memo" cols="4" rows="2" style="width: 300px;">{{$detail.memo}}</textarea>
							</td>
						</tr>
							<tr>
								<td class="head1"> 开发者</td>
								<td class="head0" colspan="3">
									{{if $updflag eq 1}}
											<select name="developer" id="developer" class="selection select2_group" style="width:100px;" required>
												<option value="">请选择</option>
												{{foreach from=$userlist item=res key=key}}
													<option value="{{$res.name}}" {{if $detail.developer eq $res.name}} selected{{/if}}>{{$res.name}}</option>
												{{/foreach}}
											</select>
										维护者：
											<select name="protector" id="protector" class="selection select2_group" style="width:100px;" required>
												<option value="">请选择</option>
												{{foreach from=$userlist item=res key=key}}
												<option value="{{$res.name}}" {{if $detail.protector eq $res.name}}selected{{/if}}>{{$res.name}}</option>
												{{/foreach}}
											</select>
									{{else}}
										<select name="developer" id="developer" class="selection select2_group" style="width:100px;" required>
											<option value="">请选择</option>
											{{foreach from=$userlist item=res key=key}}
											<option value="{{$res.name}}" {{if $userid eq $res.id}} selected{{/if}}>{{$res.name}}</option>
											{{/foreach}}
										</select>
										维护者：
										<select name="protector" id="protector" class="selection select2_group" style="width:100px;" required>
											<option value="">请选择</option>
											{{foreach from=$userlist item=res key=key}}
											<option value="{{$res.name}}" {{if $userid eq $res.id}} selected{{/if}}>{{$res.name}}</option>
											{{/foreach}}
										</select>
										&nbsp;
									{{/if}}
									优先出图平台：
									{{foreach from=$platlist item=res key=key}}
										<input type="checkbox" value="{{$res.id}}" name="platId[]" {{if $updflag && in_array($res.id,$arr_shop)}} checked {{/if}}>{{$res.name}}
									{{/foreach}}
								</td>
							</tr>
                            
                            <tr>
								<td class="head1"> 尺码信息</td>
								<td class="head0" colspan="3">
                                
                                <link rel="stylesheet" href="/fuman/kindeditor/themes/default/default.css" />
	<link rel="stylesheet" href="/fuman/kindeditor/plugins/code/prettify.css" />
	<script charset="utf-8" src="/fuman/kindeditor/kindeditor.js"></script>
	<script charset="utf-8" src="/fuman/kindeditor/lang/zh_CN.js"></script>
	<script charset="utf-8" src="/fuman/kindeditor/plugins/code/prettify.js"></script>
	<script>
		KindEditor.ready(function(K) {
			 window.editor = K.create("#sizeinfo");
		});
	</script>
	<textarea id="sizeinfo" name="sizeinfo" style="width:700px;height:300px;visibility:hidden;">{{$detail.sizeinfo}}</textarea>
				<div style=" display:none" class="errorMessage" id="errordescription"> </div>
                
								</td>
							</tr>
                            
                            
						</tbody>
					</table>
					<!--
					<table cellpadding="0" cellspacing="0" border="0" class="stdtable">
						<thead>
						<tr>
							<th colspan="12" class="head1">二、子类商品 &nbsp;&nbsp;&nbsp;
								{{if $updflag eq 1}}
								{{else}}
								<span style="margin-top:10px">
									<a href="javascript:void(0)"  onClick="showinput()"><img src="/fuman/images/add.png"></a>
								</span>
								{{/if}}
							</th>
						</tr>
						</thead>
						<tbody id="input1">
						</tbody>
					</table>
					-->
					<table cellpadding="0" cellspacing="0" border="0" class="stdtable">
						<thead>
						<!--
						{{foreach from=$arr_subskus item=rs key=key}}
							<tr>
								<td>
									<input type="text" name="subsku[{{$rs.id}}]" style="text-transform:uppercase;" id="subsku" value="{{$rs.subsku}}" class="width200" placeholder="请输入子SKU尺码">
									<input type="text" name="subskuinfo[{{$rs.id}}]" id="subskuinfo"  class="width200" value="{{$rs.memo}}" placeholder='请输入子sku尺码信息' style="margin-left: 200px;">
								&nbsp;&nbsp;<a href="javascript:void(0);" onClick="delsubsku({{$rs.id}})"> <span style="padding:5px 0 0" class="c9">删除</span></a>
								</td>
							</tr>
						{{/foreach}}
						-->
						<tr>
							<td colspan="3" id="showbuttom">
								<input type="hidden" value="{{$buyId}}" name="buyId">
								<button type="submit"  onclick="doAddorder();return false;" class="btn btn-primary" > 保存商品
								</button>
							</td>
						</tr>
						<!--
						<tr>
							<th  class="head1">三、添加商品说明</span></th>
						</tr>
						-->
						</thead>
						<tbody>
						<!--
						<tr>
							<td class="head0">
								第一步：填写好商品的SKU，及其他基础信息；<br>
								第二步：点击子类商品旁边的+号，添加子类商品。<br>
								如SKU：11007777 ：
								该SKU 有2个颜色5个尺码，则生成10个子类商品;<br>
								注意：商品SKU只允许输入数字，大小写字母，中划线和下划线 <br>
								</td>
						</tr>
						-->
						</tbody>
					</table>
				</form>
				<br />
				{{if $updflag eq 1}}
				<table cellpadding="0" cellspacing="0" border="0" class="stdtable">
					<thead>
					<tr>
						<th colspan="5" class="head1">日志信息 &nbsp;&nbsp;&nbsp;
						</th>
					</tr>
					</thead>
					<tbody >
						<tr>
							<td>序号</td><td>商品编号</td><td>操作详情</td><td>操作人</td><td>操作时间</td>
						</tr>
						{{foreach from=$logs item=res key=key}}
							<tr>
								<td>{{$res.id}}</td><td>{{$res.goods_code}}</td><td>{{$res.details}}</td><td>{{$res.username}}</td><td>{{$res.createtime}}</td>
							</tr>
						{{/foreach}}
					</tbody>
				</table>
				{{/if}}
			</div>
			<!--subcontent-->

			<!--subcontent-->

		</div>
		<!--contentwrapper-->

	</div>
	<!-- centercontent -->

</div>
<!--bodywrapper-->
<script language="javascript">
function doAddorder()
{
	if($("#bigclassID").val()=="")
	{
		alert("商品分类必须选择");
		$("#bigclassID").focus();
	   return false; 	
	}
	if($("#sku").val()=="")
	{
		alert("SKU必须填写");
		$("#sku").focus();
	   return false; 	
	}
	
	
	if($("#goods_name").val()=="")
	{
		alert("商品名称必须填写");
		$("#goods_name").focus();
	   return false; 	
	}
	if($("#address1").val()=="")
	{
		alert("采购连接必须填写");
		$("#address1").focus();
	   return false; 	
	}
	if($("#buy_days").val()=="")
	{
		alert("采购天数必须填写");
		$("#buy_days").focus();
	   return false; 	
	}
	if($("#costprice").val()=="")
	{
		alert("商品成本必须填写");
		$("#costprice").focus();
	   return false; 	
	}
	if($("#sellprice").val()=="")
	{
		alert("最低销售价必须填写");
		$("#sellprice").focus();
	   return false; 	
	}
	if($("#developer").val()=="")
	{
		alert("请选择开发者");
		$("#developer").focus();
	   return false; 	
	}
	if($("#protector").val()=="")
	{
		alert("请选择维护者");
		$("#protector").focus();
	   return false; 	
	}
	
	
	
	var contenthtml = editor.html();
	//editor1.sync();
	var description = contenthtml;
	if(description =="")
	{
	   alert("尺码信息必填写");
	   $("#description").focus();
	   return false; 
	}
	

	editor.sync();
	 document.forms['otherForm'].submit(); 
}

</script>
</body>
</html>